package example.service;

import example.mapper.SupplierMapper;
import example.pojo.Supplier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("supplierServiceImpl")
public class SupplierServiceImpl implements SupplierService {
    @Resource
    SupplierMapper supplierMapper;

    @Override
    public int add(Supplier supplier) {
        int count = 0;
        try {
            count = supplierMapper.add(supplier);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public int upd(Supplier supplier) {
        int count = 0;
        try {
            count = supplierMapper.upd(supplier);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public int del(Integer id) {
        int count = 0;
        try {
            count = supplierMapper.del(id);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public Supplier view(Integer id) {
        Supplier supplier = null;
        try {
            supplier = supplierMapper.view(id);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return supplier;
    }

    @Override
    public List<Supplier> select(String supCode, String supName, Integer pageBegin, Integer pageSize) {
        List<Supplier> supplierList = new ArrayList<>();
        try {
            supplierList = supplierMapper.select(supCode, supName, ((pageBegin - 1) * pageSize), pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return supplierList;
    }

    @Override
    public int count(String supCode, String supName) {
        int count = 0;
        try {
            count = supplierMapper.count(supCode, supName);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return count;
    }

    @Override
    public List<Supplier> all() {
        List<Supplier> supplierList = null;
        try {
            supplierList = supplierMapper.all();
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return supplierList;
    }
}
